/* THIS IS NOT A COMPLETE PROGRAM. DO NOT TRY TO COMPILE. */
/* IT IS ONLY AN EXERCISE TO CREATE A LOOP */

/* EXERCISE 2-2 (PAGE 42 IN THE BOOK) */
/* RECREATE FOR LOOP WITHOUT USING && OR || */


/* There are probably multiple ways to do this. I'm just going to do it using multiple (nested) "if" statements */

/* First I'll write the original "for" loop that is supposed to be modified just for reference */

for(i = 0; i < lim - 1 && (c = getchar()) != '\n' && c != EOF; ++i){
	s[i] = c;
}

/*
One quick note here. I know that you technically don't need to use braces {}
if there is only one line in a "for" loop or if there is only one line in an "if"
statement. But I ALWAYS use braces on everything just because I think it looks
nicer and makes things easier to read. It also specifically shows you where things
end and begin which makes it easier to troubleshoot code in the future or to make
changes to it. (As long as you indent everything correctly like I did in this code)
*/



//Now I will attempt to write that loop without using AND or OR

for(i = 0; (c = getchar()) != '\n'; ++i){
	if(i < lim - 1){
		if(c != EOF){
			s[i] = c;
		}
	}
}

/*
Now for a quick explanation of the code.

In the "for" initialization, you can use either the "i < lim - 1" condition or the "(c = getchar())" condition.
You CAN'T however use the "c != EOF" condition because "c" wouldn't have been set with the next character yet
until "(c = getchar())" is called again.  Then you simply put the 2 conditions you didn't use in the "for" loop
initialization into 2 "if" statements, with one nested inside the other. This way "s[i] = c" only gets ran if
all 3 conditions are true. Of course if you were really doing this, you would just use && in the "for" loop like
the original did because it's easier, so not sure why this was even an exercise? I guess to show you the logic
behind using &&??
*/